<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>自定义指令</title>
    <style>
      .header {
        position: absolute;
      }
    </style>
  </head>
  <body>
    <script src="https://unpkg.com/vue@next"></script>
    <div id="root"></div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            distance: 0,
          };
        },

        template: `
                <div class="header" v-pos:right="distance">
                    <input>
                </div>
                `,
      });

      app.directive("pos", (el, binding) => {
        //console.log(typeof binding.arg);
        el.style[binding.arg] = binding.value + "px";
      });

      //  app.directive("pos", {
      //        mounted(el, binding){
      //            el.style.top = binding.value + "px";
      //        },

      //        updated(el, binding){
      //            el.style.top = binding.value + "px";
      //        }
      //  });

      const vm = app.mount("#root");
    </script>
  </body>
</html>
